package com.kgc.itrip.auth;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 韩宏伟
 * 类名： CORSFilter.java
 * 创建时间： 2020/4/4 21:05
 * @version 1.0    过滤器试运行...
 */
public class CORSFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println(">>>>>>>>>>> 过滤器启动");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response1 = (HttpServletResponse) response;
        response1.setHeader("Access-Control-Allow-Origin","*");
        response1.setHeader("Access-Control-Allow-Methods","POST, GET, OPTIONS, DELETE");
        response1.setHeader("Access-Control-Max-Age"," Access-Control-Allow-Headers,token,filelength,Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers");
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
